/*
 *  Config.java
 *  business
 *
 *  Created by SunDing on 2016/11/3.
 *
 *  Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.constant;

import com.yidiandao.business.utils.FlavorUtils;
import com.yidiandao.business.utils.PreferenceUtils;
import com.yidiandao.business.utils.UIUtils;

/**
 * Host
 */
public class ServerHost {

    /**
     * 深圳，生产环境
     */
    public static final String SZ_RELEASE_HOST = "https://appnew.yidiandao.com/Api/";

    /**
     * 深圳，测试环境
     */
    public static final String SZ_TEST_HOST = "https://appnewtest.yidiandao.com/Api/";

    /**
     * 深圳，开发环境
     */
    public static final String SZ_DEV_HOST = "https://appnewdev.yidiandao.com/Api/";

    public static String getHost() {
        String host = null;
        if (PreferenceUtils.STRING_DEFAULT.equals(getSavedHost())) {
            switch (FlavorUtils.getCurrentFlavor()) {
                // 发开环境
                case Flavor.DEV:
                    host = SZ_DEV_HOST;
                    break;
                // 测试环境
                case Flavor.TEST:
                    host = SZ_TEST_HOST;
                    break;
                // 生产环境
                case Flavor.ALPHA:
                    host = SZ_RELEASE_HOST;
                    break;
            }

            return host;
        }
        return getSavedHost();
    }

    private static String getSavedHost() {
        String host = PreferenceUtils.getString(UIUtils.getContext(), Preferences.HOST, true);
        if (host.contains("http:")) {
            host = host.replace("http:", "https:");
        }
        return host;
    }
}
